﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/9/2009
 * Time: 5:15 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of DeductionEmployeeForm.
	/// </summary>
	public partial class DeductionEmployeeForm : BaseForm
	{
		public DeductionEmployeeForm() : this(new Deduction())
		{
			
		}
		
		public DeductionEmployeeForm(Deduction d)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Util.SwfUtility.SetupComboBox(comboBoxEmployee, SessionFacade.FindAllEmployees(), "Id", "Name");
			Util.SwfUtility.SetupComboBox(comboBoxPayrollCode, SessionFacade.FindAllPayrollCodes(), "Id", "Code");
			Model = d;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			Deduction d = Model as Deduction;
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			Deduction d = Model as Deduction;
			d.Employee = (comboBoxEmployee.DataSource as IList<Employee>)[comboBoxEmployee.SelectedIndex];
			d.Date = dateTimePickerDate.Value;
			d.PayrollCode = (comboBoxPayrollCode.DataSource as IList<PayrollCode>)[comboBoxPayrollCode.SelectedIndex];
			d.Amount = Util.ConvertUtility.ToDouble(textBoxAmount.Text);
			DialogResult = DialogResult.OK;
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
	}
}
